﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.DialogUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import Events.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.event.*;
    import org.aswing.border.*;
    import Display.aswingui.*;
    import L10n.*;

    public class LevelUpDialogView extends GenericDialogView {

        protected var m_level:int;
        protected var m_buyableItems:Array;
        protected var m_specialBuyableItems:Array;
        protected var m_items:Array;
        protected var m_itemWindow:JWindow;
        protected var m_giftableItems:Array;
        protected var m_pic:Loader;
        protected var m_levelIconPane;
        protected var m_panelDict:Dictionary;

        public function LevelUpDialogView(_arg1:Dictionary, _arg2:String="", _arg3:String="", _arg4:int=0, _arg5:Function=null, _arg6:int=0, _arg7:Array=null, _arg8:Array=null, _arg9:Array=null){
            this.m_level = _arg6;
            this.m_buyableItems = _arg7;
            this.m_giftableItems = _arg8;
            this.m_specialBuyableItems = _arg9;
            super(_arg1, _arg2, _arg3, _arg4, _arg5);
        }
        override protected function createInteriorHolder():JPanel{
            var _local1:JPanel;
            var _local2:JPanel;
            var _local3:JPanel;
            _local1 = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, -11, SoftBoxLayout.TOP));
            _local1.setPreferredWidth(m_bgAsset.width);
            _local1.setMinimumWidth(m_bgAsset.width);
            _local1.setMaximumWidth(m_bgAsset.width);
            _local2 = createHeaderPanel();
            ASwingHelper.prepare(_local2);
            textArea = this.createTextArea();
            ASwingHelper.prepare(textArea);
            _local1.setBorder(new EmptyBorder(null, new Insets(0, 0, 0, 0)));
            _local1.append(_local2);
            _local1.append(textArea);
            if (m_type != TYPE_MODAL){
                _local3 = createButtonPanel();
                _local1.append(ASwingHelper.verticalStrut(17));
                _local1.append(_local3);
            };
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        override protected function createTitlePanel():JPanel{
            var _local1:JPanel;
            _local1 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local2:String = ZLoc.t("Dialogs", "levelUp_title", {amount:this.m_level});
            m_acceptTextName = ZLoc.t("Dialogs", "ShareExperience");
            title = ASwingHelper.makeTextField(_local2, EmbeddedArt.TITLE_FONT, m_titleFontSize, EmbeddedArt.titleColor);
            title.filters = EmbeddedArt.titleFilters;
            var _local3:TextFormat = new TextFormat();
            _local3.size = m_titleSmallCapsFontSize;
            TextFieldUtil.formatSmallCaps(title.getTextField(), _local3);
            _local1.append(title);
            title.getTextField().height = (m_titleFontSize * 1.5);
            ASwingHelper.setEasyBorder(_local1, 4);
            return (_local1);
        }
        override protected function makeBackground():void{
            if (m_bgAsset){
                ASwingHelper.setSizedBackground(this, m_bgAsset, new Insets(0, 0, 10, 0));
            };
        }
        override protected function createCloseButtonPanel():JPanel{
            var _local2:JButton;
            var _local1:JPanel = new JPanel(ASwingHelper.softBoxLayoutVertical);
            if (this.m_type != ((((TYPE_OK) || (TYPE_MODAL))) || (TYPE_SHARECANCEL))){
                _local2 = ASwingHelper.makeMarketCloseButton();
                _local2.addEventListener(MouseEvent.CLICK, onCancelX, false, 0, true);
                _local1.append(_local2);
                ASwingHelper.setEasyBorder(_local2, 5, 0, 20, 5);
            } else {
                _local1.append(ASwingHelper.verticalStrut(20));
            };
            return (_local1);
        }
        override protected function createTextArea():JPanel{
            var _local16:String;
            var _local19:Component;
            var _local20:JPanel;
            var _local30:JPanel;
            var _local31:JTextField;
            var _local32:String;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, -5);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            var _local3:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, -3);
            ASwingHelper.setEasyBorder(_local3, 0, 100);
            var _local4:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, -10);
            var _local5:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local6:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var _local7:String = ZLoc.t("Dialogs", "NewLevel", {cityName:Global.player.cityName});
            var _local8:String = ZLoc.t("Levels", ("Level" + String(this.m_level)));
            var _local9:JTextField = ASwingHelper.makeTextField(_local7, EmbeddedArt.TITLE_FONT, 18, 2925509);
            LocaleHelper.localSetting.TextField_adjust(_local9.getTextField(), {
                font:EmbeddedArt.SYSTEM_FONT,
                embedFonts:false,
                autoSize:"left"
            });
            LocaleHelper.localSetting.matchFontAdjust_SIM_HEI(_local9, {
                topMargin:3,
                textfield:_local9.getTextField(),
                size:20
            });
            var _local10:JTextField = ASwingHelper.makeTextField(_local8, EmbeddedArt.TITLE_FONT, 18, 2925509);
            TextFieldUtil.formatSmallCaps(_local10.getTextField(), new TextFormat(EmbeddedArt.TITLE_FONT, 22));
            _local5.append(_local9);
            _local6.append(_local10);
            _local4.appendAll(ASwingHelper.verticalStrut(12), _local5, ASwingHelper.verticalStrut(15), _local6, ASwingHelper.verticalStrut(15));
            var _local11:DisplayObject = (new (m_assetDict["dialog_horizontalRule"])() as DisplayObject);
            var _local12:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            _local12.append(new AssetPane(_local11));
            _local3.append(_local4);
            _local3.append(_local12);
            var _local13:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, -26);
            if (this.m_buyableItems.length != 0){
                _local30 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
                _local31 = ASwingHelper.makeTextField(ZLoc.t("Dialogs", "Unlock"), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 14, EmbeddedArt.blueTextColor);
                _local30.append(_local31);
                _local13.append(_local30);
            };
            var _local14:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.BOTTOM);
            var _local15:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, 5);
            this.m_panelDict = new Dictionary(true);
            this.m_itemWindow = (this.parent as JWindow);
            this.m_items = new Array();
            var _local17:Array = new Array();
            var _local18:int;
            for each (_local16 in this.m_specialBuyableItems) {
                _local18++;
                if (_local18 > 4){
                    break;
                };
                _local17.unshift(this.makeItem(_local16, true));
            };
            for each (_local16 in this.m_buyableItems) {
                _local18++;
                if (_local18 > 4){
                    break;
                };
                _local17.unshift(this.makeItem(_local16, false));
            };
            for each (_local20 in _local17) {
                _local20.setPreferredHeight(131);
                _local20.setMinimumHeight(131);
                _local20.setMaximumHeight(131);
                ASwingHelper.prepare(_local20);
                _local15.append(_local20);
            };
            if (this.m_buyableItems.length == 0){
                _local15.append(ASwingHelper.verticalStrut(131));
            };
            _local14.append(_local15);
            _local13.append(_local14);
            _local3.append(_local13);
            var _local21:TextFormat = new TextFormat();
            _local21.align = TextFormatAlign.CENTER;
            _local2.append(_local3);
            var _local22:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local23:XML = Global.gameSettings.getLevelXML(this.m_level);
            var _local24:String = _local23.@icon;
            var _local25:String = Global.getAssetURL(_local24);
            if (_local24){
                this.m_pic = LoadingManager.load(_local25, this.fillLevelAsset, LoadingManager.PRIORITY_LOW);
            };
            var _local26:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, 30);
            _local22.setPreferredHeight(99);
            this.m_levelIconPane = new AssetPane();
            ASwingHelper.setEasyBorder(_local26, 30);
            var _local27:String = _local23.@message;
            var _local28:Array = _local27.split(":");
            if (_local28.length > 0){
                _local32 = ZLoc.t(_local28[0], _local28[1]);
            } else {
                _local32 = "You grew your city!";
            };
            var _local29:AssetPane = ASwingHelper.makeMultilineText(_local32, 300, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, TextFormatAlign.CENTER, 20, 9463372);
            LocaleHelper.localSetting.TextField_adjust((_local29.getAsset() as TextField), {size:16});
            _local26.appendAll(this.m_levelIconPane, _local29);
            _local22.append(_local26);
            _local2.appendAll(ASwingHelper.verticalStrut(20), _local22);
            _local1.append(_local2);
            return (_local1);
        }
        protected function makeItem(_arg1:String, _arg2:Boolean):Component{
            var itemBG:* = null;
            var unlockText:* = null;
            var str:* = _arg1;
            var special:* = _arg2;
            var ap:* = new AssetPane();
            ap.name = str;
            this.m_items.push(ap);
            itemBG = (new (m_assetDict["dialog_item"])() as DisplayObject);
            var specialBG:* = (new (m_assetDict["dialog_item_special"])() as DisplayObject);
            var verticalPanel:* = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.BOTTOM);
            var iconPanel:* = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            ASwingHelper.setSizedBackground(iconPanel, itemBG);
            iconPanel.setPreferredSize(new IntDimension(itemBG.width, itemBG.height));
            iconPanel.setMinimumSize(new IntDimension(itemBG.width, itemBG.height));
            iconPanel.setMaximumSize(new IntDimension(itemBG.width, itemBG.height));
            iconPanel.append(ap);
            var specialPanel:* = ASwingHelper.makeSoftBoxJPanelVertical();
            var centeringPanel:* = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            if (special){
                ASwingHelper.setSizedBackground(specialPanel, specialBG);
                unlockText = ASwingHelper.makeMultilineText("SPECIAL UNLOCK", (specialBG.width - 5), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, "center", 12, 0xFFFFFF);
                ASwingHelper.prepare(unlockText);
                specialPanel.append(unlockText);
            };
            centeringPanel.append(iconPanel);
            specialPanel.append(centeringPanel);
            if (!special){
                specialPanel.append(ASwingHelper.verticalStrut(7));
            };
            verticalPanel.append(specialPanel);
            var iconString:* = Global.gameSettings.getImageByName(str, "icon");
            var icon:* = LoadingManager.load(iconString, function (_arg1:Event):void{
                var _local2:*;
                var _local4:*;
                var _local5:*;
                var _local6:*;
                var _local7:*;
                var _local3:* = String(m_panelDict[_arg1.currentTarget.loader]);
                for each (_local4 in m_items) {
                    if (_local4.name == _local3){
                        _local2 = _local4;
                    };
                };
                _local5 = _arg1.currentTarget.content;
                _local6 = ((itemBG.height - _local5.height) / 2);
                _local7 = ((itemBG.width - _local5.width) / 2);
                ASwingHelper.setEasyBorder(_local2, _local6, _local7);
                _local2.setAsset(_local5);
                ASwingHelper.prepare(m_itemWindow);
            });
            this.m_panelDict[icon] = str;
            return (verticalPanel);
        }
        private function fillLevelAsset(_arg1:Event):void{
            var _local2:DisplayObject = this.m_pic.content;
            this.m_levelIconPane.setAsset(_local2);
            ASwingHelper.prepare(this);
            ASwingHelper.prepare(this.parent);
        }
        override protected function onAccept(_arg1:AWEvent):void{
            dispatchEvent(new GenericPopupEvent(GenericPopupEvent.SELECTED, YES, true));
            Global.world.viralMgr.sendLevelUpFeed(Global.player, this.m_level);
            if (m_closeCallback != null){
                removeEventListener(GenericPopupEvent.SELECTED, m_closeCallback);
            };
            closeMe();
        }

    }
}//package Display.DialogUI 
